package com.sc.nft.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.admin.request.IdRequest;
import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.entity.dto.*;
import com.sc.nft.entity.vo.ArticleDetailsVO;
import com.sc.nft.entity.vo.DaoSchoolArticlePageAdminVO;
import com.sc.nft.service.DaoSchoolArticleService;
import com.sc.nft.sup.PageRequest;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 文章表(DaoSchoolArticle)表控制层
 *
 * @author makejava
 * @since 2023-03-13 16:20:49
 */

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("admin/daoSchoolArticle")
@Api(tags = "dao学堂文章")
public class DaoSchoolArticleController {

    /**
     * 服务对象
     */
    private final DaoSchoolArticleService daoSchoolArticleService;

    @ApiOperation(value = "列表", notes = "列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/pageAdmin", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<DaoSchoolArticlePageAdminVO> pageAdmin(@RequestBody PageRequest pageRequest) {
        Page<DaoSchoolArticlePageAdminVO> daoSchoolArticlePageAdminVOPage = daoSchoolArticleService.pageAdmin(pageRequest);
        return PageResult.success(daoSchoolArticlePageAdminVOPage);
    }

    @ApiOperation(value = "删除文章", notes = "删除文章", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/deleteById", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result deleteById(@RequestBody @Validated IdRequest idRequest) {
        daoSchoolArticleService.deleteById(idRequest.getId());
        return Result.success();
    }

    @ApiOperation(value = "新增文章", notes = "新增文章", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/saveAdmin", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result saveAdmin(@RequestBody @Validated DaoSchoolArticleSaveAdminDTO daoSchoolArticleSaveAdminDTO) {
        daoSchoolArticleService.saveAdmin(daoSchoolArticleSaveAdminDTO);
        return Result.success();
    }

    @ApiOperation(value = "修改文章", notes = "修改文章", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/updateById", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result updateById(@RequestBody @Validated DaoSchoolArticleUpdateByIdAdminDTO daoSchoolArticleSaveAdminDTO) {
        daoSchoolArticleService.updateById(daoSchoolArticleSaveAdminDTO);
        return Result.success();
    }

    @ApiOperation(value = "获取没有被某个子集选中的文章", notes = "获取没有被某个子集选中的文章", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/selectByNotChildIdPageList", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<DaoSchoolArticlePageAdminVO> selectByNotChildIdPageList(@RequestBody DaoSchoolArticleNotChildIdPageListDTO daoSchoolArticleNotChildIdPageListDTO) {
        Page<DaoSchoolArticlePageAdminVO> daoSchoolArticlePageAdminVOPage = daoSchoolArticleService.selectByNotChildIdPageList(daoSchoolArticleNotChildIdPageListDTO);
        return PageResult.success(daoSchoolArticlePageAdminVOPage);
    }

    @ApiOperation(value = "获取没有被置顶的文章", notes = "获取没有被置顶的文章", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/selectByNotTopArticle", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<DaoSchoolArticlePageAdminVO> selectByNotTopArticle(@RequestBody DaoSchoolArticleNotChildIdPageListDTO daoSchoolArticleNotChildIdPageListDTO) {
        Page<DaoSchoolArticlePageAdminVO> daoSchoolArticlePageAdminVOPage = daoSchoolArticleService.selectByNotTopArticle(daoSchoolArticleNotChildIdPageListDTO);
        return PageResult.success(daoSchoolArticlePageAdminVOPage);
    }

    @ApiOperation(value = "获取首页推荐文章", notes = "获取首页推荐文章", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/homePageAdmin", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<DaoSchoolArticlePageAdminVO> homePageAdmin(@RequestBody DaoSchoolArticleNotChildIdPageListDTO daoSchoolArticleNotChildIdPageListDTO) {
        Page<DaoSchoolArticlePageAdminVO> daoSchoolArticlePageAdminVOPage = daoSchoolArticleService.homePageAdmin(daoSchoolArticleNotChildIdPageListDTO);
        return PageResult.success(daoSchoolArticlePageAdminVOPage);
    }

    @ApiOperation(value = "文章置顶", notes = "文章置顶", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/articleTop", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result articleTop(@RequestBody List<DaoSchoolArticleTopDTO> list) {
        daoSchoolArticleService.articleTop(list);
        return Result.success();
    }


    @ApiOperation(value = "取消文章置顶", notes = "取消文章置顶", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/cancelArticleTop", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result cancelArticleTop(@RequestBody List<DaoSchoolCancelArticleTopDTO> list) {
        daoSchoolArticleService.cancelArticleTop(list);
        return Result.success();
    }

    @ApiOperation(value = "通过id获取文章", notes = "通过id获取文章", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/byIdGetArticle", produces = MediaType.APPLICATION_JSON_VALUE)
    public Result<ArticleDetailsVO> byIdGetArticle(@RequestBody IdRequest idRequest) {
        return Result.success(daoSchoolArticleService.byIdGetArticle(idRequest.getId()));
    }
}
